# 名称:Backdream
# 时间2022/12/21  9:22

from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class LetterPage(BasePage):
    # url
    url = "/crm/index.php?m=message&a=index"

    # 发件箱按钮定位
    letterbox_locator = (By.ID, "t2")

    def click_letterbox(self):
        self.driver.find_element(*self.letterbox_locator).click()

    # 断言发件人定位
    letter_send_locator = (By.CSS_SELECTOR, "#form2 > table > thead > tr > th:nth-child(3)")

    def letter_send_man(self):
        return self.driver.find_element(*self.letter_send_locator).text

    # 勾选按钮定位
    chose_locator = (By.CSS_SELECTOR, "#form2 > table > tbody > tr > td:nth-child(1) > input")

    def chose_letter(self):
        self.find_element(self.chose_locator).click()

    # 批量操作定位
    more_locator = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div > div.span12.nav > div > ul > li.nav.pull-left > div > a")

    def more_use(self):
        self.find_element(self.more_locator).click()

    # 删除按钮定位
    delete_send_locator = (By.ID, "delete_send")

    def delete_send(self):
        self.find_element(self.delete_send_locator).click()

    # 断言删除成功定位
    mesg_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")

    def mesg_delete(self):
        return self.find_element(self.mesg_locator).text

    # 查看信件
    letter_look_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(2) > a")

    def letter_look(self):
        self.find_element(self.letter_look_locator).click()

    # 回复按钮
    reply_btn = (By.ID, "reply")

    def reply(self):
        self.find_element(self.reply_btn).click()

    # 内容框定位
    letter_back_locator = (By.CSS_SELECTOR, "#dialog-send > form > table > tbody > tr > td:nth-child(2) > textarea")

    def letter_back(self, msg):
        self.find_element(self.letter_back_locator).send_keys(msg)

    # 发送按钮定位
    send_btn = (By.NAME, "submit")

    def send_letter(self):
        self.find_element(self.send_btn).click()

    # 写信按钮定位器
    send_locator = (By.ID, "send")

    def write_letter(self):
        self.find_element(self.send_locator).click()

    # 全部选择定位器
    chose_all_locator = (By.CSS_SELECTOR, "#ta1 > input")

    def chose_all(self):
        self.find_element(self.chose_all_locator).click()

    # 内容输入框定位
    input_locator = (
    By.CSS_SELECTOR, "#dialog-message-send > form > table > tbody > tr:nth-child(2) > td:nth-child(2) > textarea")
    def input_letter(self,msg):
        self.find_element(self.input_locator).send_keys(msg)

    # 信件发送按钮
    send_letter_btn = (By.NAME, "submit")
    def send_let(self):
        self.find_element(self.send_letter_btn).click()

